/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.guilayer.gamemanagermenu.menucomponent;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import it.unical.canonaco.rende.igpe.game.cbv.guilayer.components.GUIGenericPawn;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.components.OrthogonalPrePlayMatchPainterManager;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.gamemanagermenu.MapAreaPanel;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.sprites.Sprite;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.sprites.SpriteSheetCache;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.component.world.Map;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.EventManager;

/**
 * @author Massimo Canonaco
 *
 */
//public class MapAreaZone016 extends MapAreaPanel {

public class MapAreaZone016 extends JPanel {

	private MapAreaPanel mapPanel;
	private Image backgroundImage;
	private OrthogonalPrePlayMatchPainterManager ort;
//	private SpriteSheetCache cache;
//	private String texturePath;
//	private String spawnTexturePath;
//	private String invalidPointPath;
//	private OrthogonalPrePlayMatchPainterManager ort;
	public MapAreaZone016(final  Map map, final java.util.Map<String,String> settings, SpriteSheetCache spriteCache, final List<GUIGenericPawn> pawnsList, Dimension dimension)
	{
		final String MAPAREAZONE_SPAWNTEXT = "mapareazone.img.info.spawntexture.path",
				MAPAREAZONE_ROLES = "mapareazone.img.info.roles",
				MAPAREAZONE_TEXTURES = "mapareazone.img.info.textures",
				INVALID_POINT_IMG = "mapareazone.img.info.invalidpoint";
//		cache = spriteCache;
		try
		{
			backgroundImage = ImageIO.read(new FileInputStream(settings.get("mapareazone.background.img")));
//			if(spawnableAreatexture == null)
//				spawnableAreatexture = ImageIO.read(new FileInputStream(settings.get("maparea.img.path")));
		} catch (IOException e) 
		{
//			spawnableAreatexture = OverallGUILayoutFactory.getInstance().getErrorImage();
			
		}
		
		this.setLayout(new BorderLayout());
//		texturePath = settings.get(MAPAREAZONE_TEXTURES);
//		spawnTexturePath = settings.get(MAPAREAZONE_SPAWNTEXT);
//		invalidPointPath = settings.get(INVALID_POINT_IMG);
		ort = new OrthogonalPrePlayMatchPainterManager(spriteCache, settings.get(MAPAREAZONE_SPAWNTEXT), 
//				(settings.get(MAPAREAZONE_ROLES)+File.separator), 
				(settings.get(MAPAREAZONE_TEXTURES)+File.separator+map.getName()+File.separator+"ortho"+File.separator), 
				settings.get(INVALID_POINT_IMG),
				map);
		ort.setting(EventManager.getInstance());
		mapPanel = new MapAreaPanel(map,settings, pawnsList,ort);
		
		GridBagLayout centerPaneLayout = new GridBagLayout();
		setLayout(centerPaneLayout);
		setSize(dimension);
		setMinimumSize(dimension);
		setPreferredSize(dimension);
		
		final int mapPanelSize = map.getArena().getSize()*mapPanel.getPIXEL_TILE();
		Dimension mapDimension = new Dimension(mapPanelSize,mapPanelSize);
		mapPanel.setPreferredSize(mapDimension);
		mapPanel.setMinimumSize(mapDimension);
		GridBagConstraints constr = new GridBagConstraints();
		constr.anchor = GridBagConstraints.CENTER;
		add(mapPanel, constr);
	}
	
	public synchronized void addML(MouseListener l) 
	{
		mapPanel.addMouseListener(l);
	}
	
	public void updateGUI() 
	{
		mapPanel.updateMapGUI();
	}
	
	@Override
	protected void paintComponent(Graphics g) 
	{
		super.paintComponent(g);
		g.drawImage(backgroundImage, 0	, 0, null);
	}

	/**
	 * @return the ort
	 */
	public OrthogonalPrePlayMatchPainterManager getOrt() {
		return ort;
	}
	
//	public void setting(Map map)
//	{
////		ort = new OrthogonalPrePlayMatchPainterManager(cache, spawnTexturePath, 
//////				(settings.get(MAPAREAZONE_ROLES)+File.separator), 
////				(texturePath+File.separator+map.getName()+File.separator+"ortho"+File.separator), 
////				invalidPointPath,
////				map);
////		ort.setting(EventManager.getIstance());
//////		
//////		mapPanel = new MapAreaPanel(map,settings, pawnsList,ort);
////		mapPanel.setting(map);
////		final int mapPanelSize = map.getArena().getSize()*mapPanel.getPIXEL_TILE();
////		Dimension mapDimension = new Dimension(mapPanelSize,mapPanelSize);
////		mapPanel.setPreferredSize(mapDimension);
////		mapPanel.setMinimumSize(mapDimension);
//	}
}
